package itcast.bos.base.test;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ActiveMqProducter_Demo1 {
	public static void main(String[] args) throws Exception {
		//新建一个链接工厂
		ConnectionFactory cf=new ActiveMQConnectionFactory();
		//获取一个链接
		Connection connection = cf.createConnection();
		//建立回话
		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
		//创建队列或话题对象
		Queue queue=session.createQueue("Hello Mamba");
		//创建生产者
		 MessageProducer p = session.createProducer(queue);
		//发布消息
		 for (int i = 0; i < 10; i++) {
			p.send(session.createTextMessage("hello mamban.No"+i));
		}
		 //事务提交
		session.commit();
		
	}
}
